<?php
class App_Splash extends Data_Base
{

    public static function currentImageUrl ()
    {
        $imgUrl = DB::select('value')
            ->from('app_system')
            ->where('name', '=', 'splashImageUrl')
            ->order_by('changed', 'desc')
            ->limit(1)
            ->execute()
            ->get('value');

        if (empty($imgUrl))
            return '';
        else
        {
            if (preg_match('/^http:\/\//', $imgUrl))
                return $imgUrl;
            else
                return 'http://' . $_SERVER['HTTP_HOST'] . $imgUrl;
        }
    }

    public static function setCurrentImageUrl($url)
    {
        if (empty($url))
            return FALSE;

        $rows = DB::update('app_system')
            ->set(array('value' => $url))
            ->where('name', '=', 'splashImageUrl')
            ->execute();

        return $rows > 0;
    }
}
